package com.qsmx.qingqiuticket.app.delegate.back;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.Nullable;

import com.qsmx.core.delegates.AtmosDelegate;
import com.qsmx.qingqiuticket.app.R;
import com.qsmx.qingqiuticket.app.databinding.DelegateBackHomeBinding;
import com.qsmx.qingqiuticket.app.event.CheckPrintEvent;
import com.qsmx.qingqiuticket.app.fusion.FusionCode;
import com.qsmx.qingqiuticket.app.util.FileUtil;
import com.qsmx.qingqiuticket.app.util.SaveHelper;

import org.greenrobot.eventbus.EventBus;

public class BackHomeDelegate extends AtmosDelegate {

    private DelegateBackHomeBinding mBinding;

    @Override
    public Object setLayout() {
        return R.layout.delegate_back_home;
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void onBindView(@Nullable Bundle savedInstanceState, View rootView) {

        mBinding = DelegateBackHomeBinding.bind(rootView);
        mBinding.tvLogAddress.setText("日志存储路径：" + FusionCode.LOG_PATH + " ");
        mBinding.tvCameraAddress.setText("相片存储路径：" + SaveHelper.getBasePath() + " ");
        mBinding.ivSetting.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                getSupportDelegate().start(new BackSettingDelegate());
            }
        });

        mBinding.ivUpdateVersion.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                getSupportDelegate().start(new BackCheckVersionDelegate());
            }
        });

        mBinding.ivMachine.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getSupportDelegate().start(new BackHardwareSettingDelegate());
            }
        });

        mBinding.ivTicketSetting.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getSupportDelegate().start(new BackInstallAndCleanDelegate());
            }
        });

        mBinding.tvBackHome.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                getSupportDelegate().pop();
                EventBus.getDefault().post(new CheckPrintEvent(new Bundle()));
            }
        });

        mBinding.tvGoToCameraAddress.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                FileUtil.openAssignFolder(requireContext(), SaveHelper.getBasePath());
            }
        });

        mBinding.tvGoToLogAddress.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                FileUtil.openAssignFolder(requireContext(), FusionCode.LOG_PATH);
            }
        });
    }
}
